﻿//分页按钮点击功能
$(document).ready(function () {
    $(".pagination>li").click(function () {
        var minShowPageSize = $(".pagination").children().eq(2).text();
        var maxShowPageSize = $(".pagination").children().eq(6).text();
        var selectText = $(this).text();
        var maxPage = $("#hfdMaxPage").val();
        var currentPage = $("#hfdPage");
        var selectPage = currentPage.val();
        if (selectPage == selectText) {
            return false;
        }
        if (!(selectText.indexOf("共") > 0 && selectText.indexOf("条数据") > 0)) {
            if (selectText == "上一页") {
                if (selectPage == 1) return false;
                else {
                    $('.pagination').children().eq(7).children().removeClass("disableCss");
                    if (selectPage - 1 <= 1) {
                        $('.pagination').children().eq(1).children().addClass("disableCss");
                        selectPage = 1
                    } else selectPage--;
                }
            }
            else if (selectText == "下一页") {
                if (selectPage >= maxPage) return false
                else {
                    $('.pagination').children().eq(1).children().removeClass("disableCss");
                    if (selectPage + 1 >= maxPage) {
                        $('.pagination').children().eq(7).children().addClass("disableCss");
                        selectPage = maxPage;
                    }
                    else selectPage++;
                }
            }
            else {
                if (selectText <= maxPage) selectPage = selectText;
                else return false;
            }
            currentPage.val(selectPage);
        }
        $("#form1").submit();
    });
});



//是否禁用分页按钮（参数为当前显示的最大分页）
function IsEnableLinkButton() {
    var maxPage = $("#hfdMaxPage").val();
    var showMaxPage = $(".pagination").children().eq(6).text();
    var currentPage = $("#hfdPage").val();
    if (currentPage == 1) {
        $('.pagination').children().eq(1).children().addClass("disableCss");
    }
    if (maxPage < showMaxPage) {
        var difference = showMaxPage - maxPage;//value = 4
        for (var i = 6; i > 6 - difference; i--) {
            var elem = $('.pagination').children().eq(i).children();
            elem.addClass("disableCss");
        }
    }
}